package cn.zk;

import org.apache.zookeeper.KeeperException;

import java.io.IOException;
import java.util.List;

public class DeleteGroup extends ConnectionWatcher{

    public void delete(String groupName){
        String path = "/" + groupName;

        try {
            zk.delete(path,-1);
            List<String> children = zk.getChildren(path,false);
            for(String child : children){
                zk.delete(path + "/" + child,-1);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (KeeperException e) {
            System.out.printf("Group %s does not exist\n",groupName);
            System.exit(1);
        }
    }

    public static void main(String[] args) throws IOException, InterruptedException {
        DeleteGroup deleteGroup = new DeleteGroup();
        deleteGroup.connect("mini1");
        deleteGroup.delete("zoo");
        deleteGroup.close();
    }

}
